package LeetCode.month01.day30;

public class No2730 {
    public static void main(String[] args) {
        System.out.println(longestSemiRepetitiveSubstring("0"));
    }
    public static int longestSemiRepetitiveSubstring(String s) {
        int n = s.length();
        char[] c = s.toCharArray();
        int num = 0;
        int left = 0;
        int res = 1;
        for (int i = 1; i < n; i++) {
            if(c[i]==c[i-1]) num++;
            while(num>1){
                if(c[left]==c[left+1]) num--;
                left++;
            }
            res = Math.max(res,i-left+1);
        }
        return res;
    }
}
